package com.lz.c;

import java.util.Arrays;
import java.util.Random;

/**
 * @ClassName Demo29
 * @Description 模拟双色球生成案例
 * @Author 2214361854
 * @Date 2022/5/27 14:47
 * @Version 1.0
 */
public class Demo29 {
    /**
     * 中奖号码：
     * 红色球：1-33号共33个里选出6个（不重复）
     * 蓝色球：1-16号共16中选出一个
     */

    private static final int[] R_ARR = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33};
    private static final int[] B_ARR = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};

    public static void main(String[] args) {
        //选中奖号码
        int[] red = selectRed(R_ARR);
        int blue = selectBlue(B_ARR);
        System.out.println("红球：" + Arrays.toString(red));
        System.out.println("蓝球：" + blue);
    }

    /**
     * 选择蓝球
     *
     * @param blue
     * @return
     */
    private static int selectBlue(int[] blue) {
        return blue[new Random().nextInt(blue.length)];
    }

    /**
     * 选择红球
     *
     * @param red
     * @return
     */
    private static int[] selectRed(int[] red) {
        int[] arr = new int[6];
        for (int i = 0; i < 6; i++) {
            arr[i] = new Random().nextInt(red.length);
            //去重
            for (int z = 0; z < i;z++){
                while (arr[i]==arr[z]){
                    i--;
                }
            }
        }
        return arr;
    }
}
